<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:Search="clr-namespace:LogGrok.Search"
                    xmlns:avalonDock="http://schemas.xceed.com/wpf/xaml/avalondock"
                    xmlns:be="clr-namespace:LogGrok.Search.Behaviors"
                    xmlns:controls="clr-namespace:LogGrok.Controls;assembly=LogGrok.Controls"
                    xmlns:infra="clr-namespace:LogGrok.Infrastructure;assembly=LogGrok.Infrastructure"
                    xmlns:infrabe="clr-namespace:LogGrok.Infrastructure.Behaviors;assembly=LogGrok.Infrastructure"
                    xmlns:infracontrols="clr-namespace:LogGrok.Infrastructure.Controls;assembly=LogGrok.Infrastructure"
                    xmlns:metroControls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
                    xmlns:toolkit="clr-namespace:Xceed.Wpf.Toolkit;assembly=Xceed.Wpf.Toolkit"
                    xmlns:properties="clr-namespace:LogGrok.Resources.Properties;assembly=LogGrok.Resources">
    
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="/LogGrok.Controls;component/Styles/ToggleButtonStyle.xaml" />
        <ResourceDictionary Source="/LogGrok.LogView;component/Styles/ListViewItemStyle.xaml" />
        <ResourceDictionary Source="/LogGrok.Controls;component/Resources/Icons.xaml" />
        <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
        <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/FlatButton.xaml" />
        <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
        <ResourceDictionary Source="pack://application:,,,/Xceed.Wpf.AvalonDock.Themes.Metro;component/Theme.xaml" />
    </ResourceDictionary.MergedDictionaries>
    
    
    <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
    <avalonDock:InverseBoolToVisibilityConverter x:Key="InverseBoolToVisibilityConverter" />
    <properties:Settings x:Key="Settings" />

    <Style TargetType="{x:Type Search:SearchDecorator}">
        <Style.Setters>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Search:SearchDecorator}">
                        <Grid x:Name="Root"
                              be:HideableRowBehavior.Index="2"
                              be:HideableRowBehavior.IsVisible="{Binding IsFilterEnabled}"
                              be:HideableRowBehavior.Row="{Binding ElementName=SearchResultsRow}">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="{Binding Default.MainViewHeightSetting, Source={StaticResource Settings}, Mode=TwoWay, Converter={Search:SettingsBindingConverter}}"/>


                                <RowDefinition Height="5" />
                                <RowDefinition x:Name="SearchResultsRow" 
                                               Height="{Binding Default.SearchViewHeightSetting, Source={StaticResource Settings},  Mode=TwoWay, Converter={Search:SettingsBindingConverter}}"/>


                            </Grid.RowDefinitions>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition />
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>
                                <ContentControl Grid.ColumnSpan="4"
                                                Margin="0,0,0,5"
                                                Content="{TemplateBinding Child}" />
                                <ToggleButton Grid.Row="1"
                                              Margin="0,0,2,0"
                                              HorizontalContentAlignment="Center"
                                              VerticalContentAlignment="Center"
                                              BorderThickness="0"
                                              IsChecked="{Binding IsCaseSensitive}"
                                              Style="{StaticResource SearchOptionToggleButtonStyle}"
                                              ToolTip="Match case">
                                    <TextBlock HorizontalAlignment="Center"
                                               VerticalAlignment="Center"
                                               FontStretch="SemiCondensed"
                                               FontWeight="Bold"
                                               Text="Aa" />
                                </ToggleButton>
                                <ToggleButton Grid.Row="1"
                                              Grid.Column="1"
                                              Margin="0,0,2,0"
                                              HorizontalContentAlignment="Center"
                                              VerticalContentAlignment="Center"
                                              BorderThickness="0"
                                              IsChecked="{Binding UseRegex}"
                                              Style="{StaticResource SearchOptionToggleButtonStyle}"
                                              ToolTip="Use Regular Expressions">
                                    <TextBlock HorizontalAlignment="Center"
                                               VerticalAlignment="Center"
                                               FontStretch="SemiCondensed"
                                               FontWeight="Bold"
                                               Text="(.*)" />
                                </ToggleButton>
                                <TextBox Grid.Row="1"
                                         Grid.Column="2"
                                         Text="{Binding SearchText,
                                                        UpdateSourceTrigger=PropertyChanged,
                                                        NotifyOnValidationError=True,
                                                        ValidatesOnDataErrors=True,
                                                        Mode=TwoWay}"
                                         controls:FindRoutedCommandBehavior.IsRoutedCommandTarget="True"
                                         metroControls:TextBoxHelper.ButtonCommand="{Binding ClearSearchCommand,
                                                                                             Mode=OneWay}"
                                         metroControls:TextBoxHelper.SelectAllOnFocus="True"
                                         metroControls:TextBoxHelper.Watermark="Search...">
                                    <TextBox.InputBindings>
                                        <KeyBinding Key="Escape" Command="{Binding ClearSearchCommand}" />
                                    </TextBox.InputBindings>
                                    <TextBox.Style>
                                        <Style BasedOn="{StaticResource MetroTextBox}" TargetType="{x:Type TextBox}">
                                            <Setter Property="metroControls:TextBoxHelper.ClearTextButton" Value="True" />
                                            <Style.Triggers>
                                                <Trigger Property="metroControls:TextBoxHelper.HasText" Value="False">
                                                    <Setter Property="metroControls:TextBoxHelper.ClearTextButton" Value="False" />
                                                </Trigger>
                                                <Trigger Property="metroControls:TextBoxHelper.HasText" Value="True">
                                                    <Setter Property="metroControls:TextBoxHelper.ClearTextButton" Value="True" />
                                                </Trigger>
                                            </Style.Triggers>
                                        </Style>
                                    </TextBox.Style>
                                </TextBox>
                            </Grid>

                            <GridSplitter Grid.Row="1"
                                          Grid.ColumnSpan="3"
                                          HorizontalAlignment="Stretch"
                                          VerticalAlignment="Stretch"
                                          Visibility="{Binding IsFilterEnabled,
                                                               Converter={StaticResource BooleanToVisibilityConverter}}" />

                            <Border x:Name="ParentBorder"
                                    Grid.Row="2"
                                    Grid.ColumnSpan="3"
                                    VerticalAlignment="Stretch"
                                    Visibility="{Binding IsFilterEnabled,
                                                         Converter={StaticResource BooleanToVisibilityConverter}}">
                                <Border.Style>
                                    <Style TargetType="Border">
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding IsFilterEnabled}" Value="False">
                                                <DataTrigger.Setters>
                                                    <Setter Property="Height" Value="0" />
                                                </DataTrigger.Setters>
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </Border.Style>
                                <avalonDock:DockingManager infrabe:DocumentCollectionBindingBehavior.CurrentDocument="{Binding CurrentDocument}"
                                                           infrabe:DocumentCollectionBindingBehavior.DocumentsSource="{Binding Documents}"
                                                           infrabe:DocumentCollectionBindingBehavior.OnDocumentCloseCommand="{Binding CloseDocument}">
                                    <avalonDock:DockingManager.LayoutItemContainerStyle>
                                        <Style TargetType="{x:Type avalonDock:LayoutItem}">
                                            <Setter Property="Title" Value="{Binding Model.Content.SearchText}" />
                                        </Style>
                                    </avalonDock:DockingManager.LayoutItemContainerStyle>
                                    <infrabe:DocumentCollectionBindingBehavior.DocumentViewTemplate>
                                        <DataTemplate>
                                            <Grid>
                                                <Grid.RowDefinitions>
                                                    <RowDefinition Height="Auto" />
                                                    <RowDefinition />
                                                </Grid.RowDefinitions>
                                                <ProgressBar x:Name="progressBar"
                                                             Height="3"
                                                             HorizontalAlignment="Stretch"
                                                             IsIndeterminate="{Binding IsIndeterninateProgress,
                                                                                       Mode=OneWay}"
                                                             Visibility="{Binding IsSearching,
                                                                                  Mode=OneWay,
                                                                                  Converter={StaticResource BooleanToVisibilityConverter}}"
                                                             Value="{Binding SearchProgress,
                                                                             Mode=OneWay}" />
                                                <infra:ListView Grid.Row="1"
                                                                FontFamily="Consolas"
                                                                IsSynchronizedWithCurrentItem="True"
                                                                IsTextSearchEnabled="False"
                                                                ItemContainerStyle="{StaticResource ItemStyle}"
                                                                ItemsSource="{Binding SearchResults}"
                                                                SelectedValue="{Binding SelectedValue}"
                                                                View="{Binding CustomView}"
                                                                VirtualizingStackPanel.IsVirtualizing="True"
                                                                VirtualizingStackPanel.VirtualizationMode="Recycling"
                                                                controls:HighlightedTextBlock.HighlightedText="{Binding SearchText}"
                                                                controls:HighlightedTextBlock.IsCaseSensitive="{Binding IsCaseSensitive}">
                                                    <infra:ListView.ItemsPanel>
                                                        <ItemsPanelTemplate>
                                                            <VirtualizingStackPanel Tag="{Binding SelectedItems, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type infra:ListView}}}">
                                                                <VirtualizingStackPanel.ContextMenu>
                                                                    <ContextMenu infra:AvalonRegion.Name="SearchContextMenu">
                                                                        <MenuItem Command="Copy" />
                                                                        <MenuItem Command="{Binding AddToScratchPad}"
                                                                                  CommandParameter="{Binding PlacementTarget.Tag,
                                                                                                             RelativeSource={RelativeSource FindAncestor,
                                                                                                                                            AncestorType={x:Type ContextMenu}}}"
                                                                                  Header="Add to scratch pad" />
                                                                    </ContextMenu>
                                                                </VirtualizingStackPanel.ContextMenu>
                                                            </VirtualizingStackPanel>
                                                        </ItemsPanelTemplate>
                                                    </infra:ListView.ItemsPanel>
                                                </infra:ListView>
                                            </Grid>
                                        </DataTemplate>
                                    </infrabe:DocumentCollectionBindingBehavior.DocumentViewTemplate>
                                    <avalonDock:DockingManager.DocumentPaneControlStyle>
                                        <Style BasedOn="{StaticResource AvalonDock_ThemeMetro_DocumentPaneControlStyle}" TargetType="{x:Type avalonDock:LayoutDocumentPaneControl}">
                                            <Setter Property="Control.Template">
                                                <Setter.Value>
                                                    <ControlTemplate TargetType="{x:Type avalonDock:LayoutDocumentPaneControl}">
                                                        <Grid ClipToBounds="True"
                                                              KeyboardNavigation.TabNavigation="Local"
                                                              SnapsToDevicePixels="True">
                                                            <Grid.RowDefinitions>
                                                                <RowDefinition Height="Auto" />
                                                                <RowDefinition Height="*" />
                                                            </Grid.RowDefinitions>
                                                            <Border Grid.RowSpan="2" Background="#00FFFFFF" />
                                                            <Grid ZIndex="1">
                                                                <Grid.ColumnDefinitions>
                                                                    <ColumnDefinition Width="Auto" />
                                                                    <ColumnDefinition />
                                                                    <ColumnDefinition Width="Auto" />
                                                                </Grid.ColumnDefinitions>
                                                                <Button Margin="5"
                                                                        Command="{Binding AddNewSearch}"
                                                                        IsTabStop="False"
                                                                        Style="{StaticResource ChromelessButtonStyle}">
                                                                    <Button.Content>
                                                                        <Rectangle Width="15"
                                                                                   Height="15"
                                                                                   Fill="{Binding RelativeSource={RelativeSource AncestorType=Button},
                                                                                                  Path=Foreground}">
                                                                            <Rectangle.OpacityMask>
                                                                                <VisualBrush Stretch="Fill" Visual="{StaticResource appbar_add}" />
                                                                            </Rectangle.OpacityMask>
                                                                        </Rectangle>
                                                                    </Button.Content>
                                                                </Button>
                                                                <avalonDock:DocumentPaneTabPanel Name="HeaderPanel"
                                                                                                 Grid.Row="0"
                                                                                                 Grid.Column="1"
                                                                                                 Margin="2,0,2,0"
                                                                                                 IsItemsHost="True"
                                                                                                 KeyboardNavigation.TabIndex="1" />
                                                                <avalonDock:DropDownButton Name="MenuDropDownButton"
                                                                                           Grid.Column="2"
                                                                                           VerticalAlignment="Center"
                                                                                           Focusable="False"
                                                                                           Style="{StaticResource AvalonDock_ThemeMetro_ToolButtonStyle}">
                                                                    <avalonDock:DropDownButton.DropDownContextMenu>
                                                                        <avalonDock:ContextMenuEx ItemsSource="{Binding Model.ChildrenSorted, RelativeSource={RelativeSource TemplatedParent}}">
                                                                            <avalonDock:ContextMenuEx.ItemContainerStyle>
                                                                                <Style BasedOn="{StaticResource {x:Type MenuItem}}" TargetType="{x:Type avalonDock:MenuItemEx}">
                                                                                    <Setter Property="HeaderedItemsControl.HeaderTemplate" Value="{Binding Path=Root.Manager.DocumentPaneMenuItemHeaderTemplate}" />
                                                                                    <Setter Property="HeaderedItemsControl.HeaderTemplateSelector" Value="{Binding Path=Root.Manager.DocumentPaneMenuItemHeaderTemplateSelector}" />
                                                                                    <Setter Property="avalonDock:MenuItemEx.IconTemplate" Value="{Binding Path=Root.Manager.IconContentTemplate}" />
                                                                                    <Setter Property="avalonDock:MenuItemEx.IconTemplateSelector" Value="{Binding Path=Root.Manager.IconContentTemplateSelector}" />
                                                                                    <Setter Property="MenuItem.Command" Value="{Binding Path=., Converter={StaticResource ActivateCommandLayoutItemFromLayoutModelConverter}}" />
                                                                                </Style>
                                                                            </avalonDock:ContextMenuEx.ItemContainerStyle>
                                                                        </avalonDock:ContextMenuEx>
                                                                    </avalonDock:DropDownButton.DropDownContextMenu>
                                                                </avalonDock:DropDownButton>
                                                            </Grid>
                                                            <Border Name="ContentPanel"
                                                                    Grid.Row="1"
                                                                    Grid.Column="0"
                                                                    HorizontalAlignment="Stretch"
                                                                    VerticalAlignment="Stretch"
                                                                    Background="{TemplateBinding Control.Background}"
                                                                    BorderBrush="{TemplateBinding Control.BorderBrush}"
                                                                    BorderThickness="{TemplateBinding Control.BorderThickness}"
                                                                    KeyboardNavigation.DirectionalNavigation="Contained"
                                                                    KeyboardNavigation.TabIndex="2"
                                                                    KeyboardNavigation.TabNavigation="Cycle"
                                                                    Padding="0,1,0,2">
                                                                <ContentPresenter Name="PART_SelectedContentHost"
                                                                                  Margin="0,2,0,2"
                                                                                  ContentSource="SelectedContent"
                                                                                  SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
                                                            </Border>
                                                        </Grid>
                                                        <ControlTemplate.Triggers>
                                                            <MultiDataTrigger>
                                                                <MultiDataTrigger.Conditions>
                                                                    <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=Model.SelectedContent.IsActive}" Value="True" />
                                                                    <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=Model.SelectedContent.IsLastFocusedDocument}" Value="True" />
                                                                </MultiDataTrigger.Conditions>
                                                                <Setter Property="Control.Background" Value="{DynamicResource AvalonDock_ThemeMetro_BaseColor31}" />
                                                            </MultiDataTrigger>
                                                            <MultiDataTrigger>
                                                                <MultiDataTrigger.Conditions>
                                                                    <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=Model.SelectedContent.IsActive}" Value="False" />
                                                                    <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=Model.SelectedContent.IsLastFocusedDocument}" Value="True" />
                                                                </MultiDataTrigger.Conditions>
                                                                <Setter Property="Control.Background" Value="{DynamicResource AvalonDock_ThemeMetro_BaseColor30}" />
                                                            </MultiDataTrigger>
                                                            <Trigger Property="UIElement.IsEnabled" Value="False">
                                                                <Setter Property="Control.Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
                                                            </Trigger>
                                                            <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=Self}, Path=Model.ChildrenCount}" Value="0">
                                                                <Setter TargetName="MenuDropDownButton" Property="UIElement.Visibility" Value="Collapsed" />
                                                            </DataTrigger>
                                                        </ControlTemplate.Triggers>
                                                    </ControlTemplate>
                                                </Setter.Value>
                                            </Setter>
                                        </Style>
                                    </avalonDock:DockingManager.DocumentPaneControlStyle>
                                    <avalonDock:LayoutRoot>
                                        <avalonDock:LayoutPanel Orientation="Horizontal">
                                            <avalonDock:LayoutDocumentPane />
                                        </avalonDock:LayoutPanel>
                                    </avalonDock:LayoutRoot>
                                </avalonDock:DockingManager>
                            </Border>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style.Setters>
    </Style>
</ResourceDictionary>
